package com.demo.juc.jvm;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2023/2/24 15:18
 * @Version: 1.0
 */
public class DeadLockDemo {

    private static Object lock1 = new Object();
    private static Object lock2 = new Object();

    public static void main(String[] args) {

        new Thread(()->{
            synchronized (lock1){
                try {
                    System.out.println(Thread.currentThread().getName()+"===start");
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (lock2){
                    System.out.println(Thread.currentThread().getName()+"===end");
                }
            }
        },"A").start();

        new Thread(()->{
            synchronized (lock2){
                try {
                    System.out.println(Thread.currentThread().getName()+"===start");
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (lock1){
                    System.out.println(Thread.currentThread().getName()+"===end");
                }
            }
        },"B").start();

    }

    //Attaching to core id from executable 10992, please wait...
}
